from django.shortcuts import render
from django.shortcuts import HttpResponse
from django.db.models import F,Q

from .myforms import StudentForm
from .models import Student

# Create your views here.

def index(request):
    if request.method == "GET":
        form = StudentForm()
        return render(request, 'student2.html',{"form":form})
    if request.method == "POST":
        form = StudentForm(request.POST)
        if form.is_valid():
            student = Student(**form.cleaned_data)
            student.save()
        else:
            return render(request, 'student2.html', {"form": form})
        return HttpResponse("ok")

def hoot(request):
    cc=Student.objects.filter(Q(name__startswith='李') & Q(age__gt=20)).update(age=F('age')-1)
    print(cc)
    return HttpResponse('ok')
